using Godot;
using System;

public partial class UiGameOver : Ui
{
	private Button _backGame;
	private Button _endGame;
	private Timer _timer;
	private TextEdit _text;
	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{
		_backGame = GetNode<Button>("%ButtonBackGame");
		_endGame = GetNode<Button>("%ButtonEndGame");
		_timer = GetNode<Timer>("%Timer");
		_text = GetNode<TextEdit>("%time");
		_backGame.ButtonUp += BackGame;
		_endGame.ButtonUp += EndGame;
		_timer.Timeout += BackTittle;
	}

	// Called every frame. 'delta' is the elapsed time since the previous frame.
	public override void _Process(double delta)
	{
		
		if(_timer.TimeLeft != 0)
		{
			_text.Text = (int)_timer.TimeLeft + "秒后返回游戏标题";
		}
	}

    public override void enter()
    {
        base.enter();
		_timer.Start(5);
    }

    public void BackTittle()
	{
		close_self();
		var UIControl = GetNode<UIControl>("/root/UIControl");
		UIControl.GetGuiViewManager().open_view("UiStart");
		
	}

	public void EndGame()
	{
		GetTree().Quit();
	}

	public void BackGame()
	{}
}
